// import VueRouter from 'vue-router'
import { createRouter, createWebHistory } from "vue-router";
import GetNetUtil from "../utils/GetNetUtil";
import { Toast } from "vant";
const routes = [
  // {
  //   path: "/",
  //   name: "home",
  //   meta: { keepAlive: true },
  //   component: () => import("@v/home/index.vue"),
  // },
  // {
  //   path: "/service-manager/index",
  //   name: "service-manager",
  //   component: () => import("@v/home/service-manager/index.vue"),
  // },
  // {
  //   path: "/service-manager/service-more",
  //   name: "service-more",
  //   component: () => import("@v/home/service-manager/service-more.vue"),
  // },
  // {
  // path: "/micro-platform/index",
  //   name: "micro-platform",
  //   component: () => import("@v/home/micro-platform/index.vue"),
  // },
  // {
  //   path: "/micro-platform/list",
  //   name: "micro-list",
  //   component: () => import("@v/home/micro-platform/list.vue"),
  // },
  // {
  //   path: "/micro-platform/orderList",
  //   name: "micro-orderList",
  //   component: () => import("@v/home/micro-platform/orderList.vue"),
  // },
  // {
  //   path: "/micro-platform/orderPage",
  //   name: "micro-orderPage",
  //   component: () => import("@v/home/micro-platform/orderPage.vue"),
  // },
  // {
  //   path: "/micro-platform/pdf",
  //   name: "micro-pdf",
  //   component: () => import("@v/home/micro-platform/pdf.vue"),
  // },
  // {
  //   path: "/base/areas",
  //   name: "areas",
  //   component: () => import("@v/home/base/areas.vue"),
  // },
  // {
  //   path: "/evaluation-data/index",
  //   name: "evaluation-data",
  //   component: () => import("@v/home/evaluation-data/index.vue"),
  // },
  {
    path: "/",
    name: "/",
    meta: { keepAlive: true },
    component: () => import("@v/pan-view/index.vue"),
  },

  //综合满意度
  {
    path: "/zhmyd/index",
    name: "zhmyd",
    component: () => import("@v/zhmyd/index.vue"),
  },
  // 投诉
  {
    path: "/tousu/index",
    name: "tousu",
    component: () => import("@v/tousu/index.vue"),
  },
  // 手机
  {
    path: "/mobile/index",
    name: "mobile",
    component: () => import("@v/mobile/index.vue"),
  },

  // 家宽
  {
    path: "/jiakuan/index",
    name: "jiakuan",
    component: () => import("@v/jiakuan/index.vue"),
  },

  // 政企
  {
    path: "/zhengqi/index",
    name: "zhengqi",
    component: () => import("@v/zhengqi/index.vue"),
  },

  //触点
  {
    path: "/chudian/index",
    name: "chudian",
    component: () => import("@v/chudian/index.vue"),
  },
];

const router = createRouter({
  // 指定路由的模式,此处使用的是hash模式
  history: createWebHistory(),
  // history:createWebHashHistory(),
  routes, // short for `routes: routes`
});

// 校验SSO登录
// 路由转发之前操作
router.beforeEach((to, from, next) => {
  let env = import.meta.env;
  console.log("env", env);
  console.log("path", to.path);
  if (to.path == "/ssoLoginNew" && env.VITE_APP_ENV != "development") {
    document.title = "O了";
    let param = to.query;
    GetNetUtil.requestPost("/getToken", "", param, checkSso);
    async function checkSso(resp) {
      if (resp.resultCode === "200") {
        sessionStorage.setItem("token", encodeURI(resp.data.token));
        console.log(encodeURI(resp.data.token));
        if (param.menuId == 100001) {
          next({ path: "/service-manager/index" });
        }
        if (param.menuId == 100002) {
          next({ path: "/micro-platform/index" });
        }
      } else {
        Toast(resp.resultDesc);
      }
    }
  } else if (to.path == "/ssoLoginFor5g") {
    document.title = "工信部测评数据";
    let param = to.query;
    GetNetUtil.requestPost("/token/getTokenFor5g", "", param, checkSso);
    async function checkSso(resp) {
      if (resp.resultCode === "200") {
        sessionStorage.setItem("token", encodeURI(resp.data.token));
        console.log(encodeURI(resp.data.token));
        next({ path: "/evaluation-data/index" });
      } else {
        Toast(resp.resultDesc);
      }
    }
  } else {
    console.log("11");
    if (env.VITE_APP_ENV != "production") {
      console.log("22");
      let token = "";
      if (env.VITE_APP_ENV === "development") {
        token =
          "1orfY2mPyRYQh+hI5RI/nJ9/DWsqACu1CcmG4e6Sas7LHKWrwjVFtQ7D0OEmoGK6YgnVHSH242RN%0AzdmSDzbMwr2GDCcNlkaJ9oD+c022mTvQzeTaHZgUYTwxA2sRTM/YTGei6l7dTxM1caiOtedb69eb%0A/mhlDqzKSXNQCFfA2VI=%0A";
      }
      if (env.VITE_APP_ENV === "staging") {
        token = "5F71293582408CC955D1A41FC434D29A";
      }
      sessionStorage.setItem("token", token);
    }
    next();
  }
});

// Vue-router新版本中，需要使用createRouter来创建路由
export default router;
